module CompanyHelper

  def owner_filter_list(selected)
    filter_link_list("owner", Company::OWNER_TYPES, selected, true)
  end
  
  def state_filter_list(selected)
    filter_link_list("state", ApplicationController::STATE_ABBR, selected, false)
  end
  
  def filter_link_list(attribute, options, selected, show_all)

    newparams = params.clone
    
    # zero out the page attribute
    newparams[:page] = nil
    list = ""

    if show_all
      if newparams[attribute]
        newparams[attribute] = nil
        list = link_to( "All", url_for(newparams) )
      else
        list = "All"
      end
      list += "<br/>"
		end
		
    options.keys.sort.each do |opt| 
      if opt.eql?(selected.to_s)
        list += options[opt].to_s
      else
        newparams[attribute] = opt # override the parameter value to change the link
        list += link_to( options[opt].to_s, url_for(newparams) ) # create the updated link
      end
      
      list += "<br/>" 
    end
    
    return list
  end
  
end